package part1;

import java.util.Vector;

/**
 * <p>Title: Project 13 part 1</p>
 * <p>Description: CS 235 Project #13 pt. 
 *       Shows how to use the Comparable interface for sorting.</p>
 * @author Anthony Varghese
 * @date   February 5th 2012
 * @version 1.0
 */

class Data {
	private int   idata;
	private float rdata;
	public Data( int i, float r){
		idata = i;
		rdata = r;
	}
	public Data( Data s){
		idata = s.idata;
		rdata = s.rdata;
	}
	public String toString(){
		return "[ " + idata + ", " + rdata + "]";
	}
}

public class Part1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Create an empty Vector
		Vector dvec = new Vector();

		// Add Data objects with random int and float data
		final int SIZE = 20;
		for (int i=0; i<SIZE; i++) {
			int   itemp = (int) (Math.random() * SIZE );
			float temp = (float) Math.random() * SIZE / 10.0f;
			dvec.add( new Data( itemp , temp ) );
		}
		
		// Print unsorted version
		System.out.println("Starting data: ");
		for (Object d : dvec)
			System.out.println( d );
				
		// Sort the darr array in order of increasing values of the int data member
		java.util.Collections.sort( dvec );
				
		// Print sorted version
		System.out.println("\n\nSorted by first data member: ");
		for (Object d : dvec)
			System.out.println( d );
	}
}